package com.xybbs.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.util.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;

import com.xybbs.entity.Users;

public class LoginInterceptor implements HandlerInterceptor{
	 @Override
	    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
	        Users user = (Users) request.getSession().getAttribute("user");
	        if(StringUtils.isEmpty(user)){
	            request.setAttribute("myInfo","当前未登录请先登录");
	            request.getRequestDispatcher("/main/toMainPage.do").forward(request,response);
	            return false;
	        }else{
	            return true;
	        }
	    }
}
